<template>
  <div class="app-container">
    <el-card class="content-edit">
      <div slot="header">首页宣传语</div>
      <el-form ref="form" :model="form" label-width="120px">
        <el-form-item label="内容">
          <el-input v-model="form['content']" type="textarea" rows="5" maxlength="30" show-word-limit/>
          <div class="remarks"><span class="symbol">⁎</span>注：内容长度请控制在30字符内</div>
        </el-form-item>
        <el-form-item>
          <el-button :loading="loading" type="primary" @click="onSubmit">提交</el-button>
          <el-button @click="$router.back()">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
  export default {
    name: 'HomepageSlogan',
    data() {
      return {
        loading: false,
        form: {
          // 内容
          content: ''
        }
      }
    },
    mounted(){
      this.loadData();
    },
    methods: {
      loadData() {
        (async () => {
          const result = await this.$service.applicationGetWxAppSlogan();
          // const result = await this.$service.applicationToRequestWxCloudApi({action: 'getSlogan'});
          if (result.code === 0) {
            // this.form['content'] = result.data['list']['content'] || '';
            this.form['content'] = result.data['content'] || '';
          }
        })();
      },
      // 提交
      onSubmit() {
        this.$refs.form.validate(valid => {
          if (valid) {
            (async () => {
              const params = Object.assign({}, this.form);
              const result = await this.$service.applicationSaveWxAppSlogan(params);
              // const result = await this.$service.applicationToRequestWxCloudApi({
              //   action: 'updateSlogan',
              //   params: JSON.stringify(params)
              // });
              if (result.code === 0) {
                this.$message.success('操作成功~');
              } else {
                this.$message.error(result.msg);
              }
            })();
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
    }
  }
</script>

